#include "obstacle.h"

obstacle::obstacle(int x,int y,int width,int height)
{
    //成员初始化
    this->x=x;
    this->y=y;
    this->width=width;
    this->height=height;
}
int obstacle::getX()
{
    return this->x;

}
int obstacle::getY()
{
    return this->y;

}
void obstacle::setX(int x)
{
    this->x=x;
}
void obstacle::setY(int y)
{
    this->y=y;
}
int obstacle::getWidth()
{
    return this->width;

}
int obstacle::getHeight()
{
    return this->height;

}
Wall::Wall(int x, int y, int width, int height)
    :obstacle(x,y,width,height)
{
    srand(time(NULL));
    this->img.load(QString(":/background/Image/wall%1.png").arg(rand()%2+1));  //两种墙，随机取出
}
QPixmap Wall::getImg()
{
    return this->img;
}
bool Wall::isCollision(int y)
{
    QRect rect_1(this->getX(),this->getY(),this->getWidth(),this->getHeight());
    if(this->getX()==40&&this->getY()==y) return true;
    else return false;
}
void Wall::move()
{
    this->setX(this->getX()-30);
}
bool Wall::done()
{
    if(this->getX()<=(-this->getWidth()))
    {
        return true;
    }
    else
    {
        return false;
    }
}
